package com.itcoon.cloud.framework.mybatis.typehandler;

import com.itcoon.cloud.framework.utils.JsonUtils;

public class ClassToJsonTypeHandler<T> extends AbstractToStringTypeHandler<T> {

    private final Class<T> objectType;

    protected ClassToJsonTypeHandler(Class<T> objectType) {
        this.objectType = objectType;
    }

    @Override
    String convertNonNull(T ts) {
        return JsonUtils.writeToJson(ts);
    }

    @Override
    T reverseNonNullConvert(String column) {
        return JsonUtils.readFromJson(column, objectType);
    }


}
